import requests
from requests import RequestException

try:
    # response = requests.get('https://www.baidu.com', timeout=1)
    response = requests.get('http://httpbin.org/get', timeout=0.5)  # 没有在0.5秒内响应就报错
    print(response.status_code)
except RequestException:
    print('timeout')
